package com.sanhe.rfmuscle.view;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.menu.app.db.bean.CusUsage;
import com.menu.app.db.bean.Custom;
import com.menu.app.fragment.FullScreenDlg;
import com.sanhe.rfmuscle.adapter.ParamAdapter;
import com.sanhe.rfmuscle.databinding.ParamDlgBinding;

import java.util.List;

public class ParamDlg extends FullScreenDlg {

    View mExitView;
    ParamDlgBinding binding;
    List<CusUsage> data;
    Custom custom;
    boolean isAdmin;
    Context context;

    public void setParam(Context context, List<CusUsage> data, Custom custom, boolean isAdmin) {
        this.data = data;
        this.custom = custom;
        this.isAdmin = isAdmin;
        this.context = context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (mExitView == null) {
            binding = ParamDlgBinding.inflate(inflater, container, false);
            mExitView = binding.getRoot();
            binding.close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dismiss(false, null);
                }
            });
            binding.list.setLayoutManager(new LinearLayoutManager(getActivity()));
            ParamAdapter adapter = new ParamAdapter(context, this, data);
            binding.list.setAdapter(adapter);
        } else if (mExitView.getParent() instanceof ViewGroup) {
            ((ViewGroup) mExitView.getParent()).removeView(mExitView);
        }

        return mExitView;
    }

    public void toWork(CusUsage usage) {
        if (isAdmin) {
            return;
        }
        dismiss(true, usage);
    }
}